package com.jielihaofeng.nio.bytebuffer;

import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.charset.StandardCharsets;

import static com.jielihaofeng.nio.bytebuffer.ByteBufferUtil.debugAll;

/**
 * @description 测试 Gather 写 [集中写入]
 * @author Johnnie Wind
 * @date 2021/10/1 20:47
 */
public class TestGatheringWrites {

    public static void main(String[] args) {

        ByteBuffer b1 = StandardCharsets.UTF_8.encode("hello");
        ByteBuffer b2 = StandardCharsets.UTF_8.encode("world");
        ByteBuffer b3 = StandardCharsets.UTF_8.encode("你好");

        try(FileChannel channel = new RandomAccessFile("words2.txt","rw").getChannel()){
            channel.write(new ByteBuffer[]{b1,b2,b3});
            debugAll(b1);
            debugAll(b2);
            debugAll(b3);
        }catch (IOException e){

        }

    }

}
